package com.qdlc.p2p.biz.service.impl;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.qdlc.p2p.biz.service.UserAutoTenderLogService;
import com.qdlc.p2p.common.util.StringUtil;
import com.qdlc.p2p.dal.common.model.jpa.PageDataList;
import com.qdlc.p2p.dal.common.model.jpa.QueryParam;
import com.qdlc.p2p.dal.dao.UserAutoTenderLogDao;
import com.qdlc.p2p.dal.dto.Borrow;
import com.qdlc.p2p.dal.dto.User;
import com.qdlc.p2p.dal.dto.UserAutoTenderLog;
import com.qdlc.p2p.dal.model.UserAutoTenderLogModel;

@Service("userAutoTenderLogService")
public class UserAutoTenderLogServiceImpl implements UserAutoTenderLogService {
	@Resource
	private UserAutoTenderLogDao userAutoTenderLogDao;
	
	@Override
	public PageDataList<UserAutoTenderLogModel> getUserAutoTenderLogList(
			int pageNumber, int pageSize, UserAutoTenderLogModel model) {
		QueryParam param = QueryParam.getInstance().addPage(pageNumber,
				pageSize);
		if(StringUtil.isNotBlank(model.getUserName())){
			param.addParam("user.userName", model.getUserName());
		}
		PageDataList<UserAutoTenderLog> userAutoTenderLogList= userAutoTenderLogDao.findPageList(param);
		PageDataList<UserAutoTenderLogModel> modelList = new PageDataList<UserAutoTenderLogModel>();
		modelList.setPage(userAutoTenderLogList.getPage());
		List<UserAutoTenderLogModel> list = new ArrayList<UserAutoTenderLogModel>();
		for(UserAutoTenderLog userAutoTenderLog: userAutoTenderLogList.getList()){
			User user = userAutoTenderLog.getUser();
			Borrow borrow = userAutoTenderLog.getBorrow();
			UserAutoTenderLogModel autoTenderLogmodel = UserAutoTenderLogModel.instance(userAutoTenderLog);
			autoTenderLogmodel.setBorrowName(borrow.getName());
			autoTenderLogmodel.setUserName(user.getUserName());
			autoTenderLogmodel.setUuid(borrow.getUuid());
			list.add(autoTenderLogmodel);
		}
		modelList.setList(list);
		return modelList;
	}

	@Override
	public void save(UserAutoTenderLog userAutoTenderLog) {
		userAutoTenderLogDao.save(userAutoTenderLog);
	}

}
